package cn.yza.设计模式.代理模式.动态代理.demo2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author Honglixi
 * @create 2021-11-01 20:19
 */
public class MySellHandler implements InvocationHandler {

    private Object target = null;

    public MySellHandler(Object target) {
        //目标对象
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //调用目标方法
        Object res = null;
        res = method.invoke(target, args);
        //增强功能
        if (res != null) {
            Float price = (Float) res;
            price += 20;
            res = price;
        }
        return res;
    }
}
